#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
'''
@author: yuejl
@application:
@contact: lewyuejian@163.com
@file: takes.py
@time: 2021/10/17 0017 12:45
@desc:
'''
class Singleton(object):
    """
        单例模式（装饰类的类装饰器）
    """

    instances = {}

    def __init__(self, cls: type):
        self.cls = cls
        self.cls_name = cls.__name__

    def __call__(self, *args, **kwargs):
        if self.cls_name not in self.instances:
            self.instances[self.cls_name] = self.cls(*args, **kwargs)
        return self.instances[self.cls_name]